Skip to content

Fix #16298: Allow customization of headers in Route#16355

Closed
aviralgarg05 wants to merge 3 commits intoknative:mainfrom
aviralgarg05:fix-16298-custom-headers
Closed

Fix #16298: Allow customization of headers in Route#16355
aviralgarg05 wants to merge 3 commits intoknative:mainfrom
aviralgarg05:fix-16298-custom-headers

Conversation

@aviralgarg05
Copy link
Copy Markdown
Contributor

Pull Request Description

Fixes #16298

Proposed Changes

  • API Development: Added the AppendHeaders field (type map[string]string) to the TrafficTarget struct in pkg/apis/serving/v1/route_types.go. This allows users to specify custom HTTP headers for specific traffic targets in a Knative Route.
  • Validation: Implemented validateAppendHeaders in pkg/apis/serving/v1/route_validation.go to ensure that all keys provided in AppendHeaders are valid HTTP header names according to RFC 7230 and that the field is not present in the Status of the Route.
  • Ingress Propagation: Updated the Ingress generation logic in pkg/reconciler/route/resources/ingress.go. The AppendHeaders from the Route's TrafficTarget are now merged with system-level headers (like activator headers) using kmeta.UnionMaps and propagated to the IngressBackendSplit.
  • DeepCopy Logic: Manually updated pkg/apis/serving/v1/zz_generated.deepcopy.go to include deep copy support for the new AppendHeaders map, ensuring the field survives reconciliation cycles.
  • Unit Testing:
    • Added test cases to pkg/apis/serving/v1/route_validation_test.go to verify valid and invalid header configurations.
    • Added TestMakeIngressSpecWithAppendHeaders to pkg/reconciler/route/resources/ingress_test.go to confirm that headers are correctly passed through to the networking layer.

Release Note

Added `AppendHeaders` field to `TrafficTarget` in the Route API (v1) to allow specifying additional HTTP headers to be added before forwarding a request to the destination service.

    - Add AppendHeaders to TrafficTarget
    - Update Route validation
    - Update Ingress generation to propagate AppendHeaders
    - Add unit tests
    - Manually update DeepCopy for AppendHeaders
@knative-prow knative-prow Bot requested review from dprotaso and skonto January 25, 2026 14:38
@knative-prow knative-prow Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 25, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented Jan 25, 2026

Hi @aviralgarg05. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented Jan 25, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: aviralgarg05
Once this PR has been reviewed and has the lgtm label, please assign dprotaso for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.20%. Comparing base (2d3f345) to head (ea18c4a).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16355      +/-   ##
==========================================
- Coverage   80.23%   80.20%   -0.03%     
==========================================
  Files         216      216              
  Lines       13440    13450      +10     
==========================================
+ Hits        10784    10788       +4     
- Misses       2293     2298       +5     
- Partials      363      364       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@linkvt
Copy link
Copy Markdown
Member

linkvt commented Jan 25, 2026

Hi @aviralgarg05 ,
thanks for the PR, this topic is a bit more complicated though as the PR is only one side of solving this problem.
The other side is net-... implementations like https://github.com/knative-extensions/net-kourier that follow the specification to actually add the headers to the requests they route to the knative service.

I'm not experienced enough to know extending the spec would work especially considering that adding headers might not be supported by all implementations, I guess @dprotaso has more background on what could be done?

@dprotaso
Copy link
Copy Markdown
Member

/hold

We don't want to accept spec changes without a discussion. Generally it requires us to follow the feature track process

https://github.com/knative/community/blob/main/mechanics/FEATURE-TRACKS.md

@knative-prow knative-prow Bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 26, 2026
@dprotaso
Copy link
Copy Markdown
Member

Also note the change as is has security concerns because you're able to set any arbitrary header which can mess up scale to zero activation.

@aviralgarg05
Copy link
Copy Markdown
Contributor Author

So can you guide me on how we will be moving forward with this PR?

@dprotaso
Copy link
Copy Markdown
Member

dprotaso commented Feb 2, 2026

@aviralgarg05 frankly I'm unsure.

The other issue for me is expanding on our Route type might not be worth it if we can sort out how we can leverage HTTPRoute to point to Knative Revisions directly.

@aviralgarg05
Copy link
Copy Markdown
Contributor Author

Thanks for the feedback @dprotaso.

I understand the concerns regarding security and the potential shift towards HTTPRoute.

Since expanding Route might not be the right direction, could you point me to any tracking
issue or discussion regarding the HTTPRoute integration? I'd be happy to help contribute to
that effort if it solves the underlying need for header customization.

Alternatively, if the HTTPRoute transition is further out, would you be open to a more
restricted version of this PR (e.g., allow-listing specific headers) to address the immediate
use case safely?

Let me know how you'd prefer to proceed.

@dprotaso
Copy link
Copy Markdown
Member

dprotaso commented Feb 5, 2026

It seems the work that would enable this has sorta stalled out upstream - kubernetes-sigs/gateway-api#3608

Alternatively, if the HTTPRoute transition is further out, would you be open to a more
restricted version of this PR (e.g., allow-listing specific headers) to address the immediate
use case safely?

I think it's probably best for me to get more information. For example if you're baking a fixed header and value in every incoming request is there a reason why this can't be configured in the application? eg. just set that option as an environment variable etc.

@aviralgarg05
Copy link
Copy Markdown
Contributor Author

It seems the work that would enable this has sorta stalled out upstream - kubernetes-sigs/gateway-api#3608

Alternatively, if the HTTPRoute transition is further out, would you be open to a more
restricted version of this PR (e.g., allow-listing specific headers) to address the immediate
use case safely?

I think it's probably best for me to get more information. For example if you're baking a fixed header and value in every incoming request is there a reason why this can't be configured in the application? eg. just set that option as an environment variable etc.

That's a fair point! The reason we can't do it in the app is that these headers are for security tools that check the request before it even arrives. Since those tools see the request first, the app doesn't have a chance to add them.

I’m also definitely open to the restricted version you suggested if you think that's a safer way to go!

@dprotaso
Copy link
Copy Markdown
Member

dprotaso commented Feb 5, 2026

Also what networking layer are you using?

That's a fair point! The reason we can't do it in the app is that these headers are for security tools that check the request before it even arrives. Since those tools see the request first, the app doesn't have a chance to add them.

Can you clarify and expand on that? If you're configuring this security tool to check for these headers and to address this you want to add headers to the inbound request then that seems like you're introducing the constraint on yourself?

@aviralgarg05
Copy link
Copy Markdown
Contributor Author

aviralgarg05 commented Feb 5, 2026

Also what networking layer are you using?

That's a fair point! The reason we can't do it in the app is that these headers are for security tools that check the request before it even arrives. Since those tools see the request first, the app doesn't have a chance to add them.

Can you clarify and expand on that? If you're configuring this security tool to check for these headers and to address this you want to add headers to the inbound request then that seems like you're introducing the constraint on yourself?

I am using Istio. The security tool is shared infrastructure that requires these headers to identify the application and apply the right policies. Since I don't manage that service directly, adding headers at the Route level is the best way for me to handle the integration

@dprotaso
Copy link
Copy Markdown
Member

dprotaso commented Feb 5, 2026

The security tool is shared infrastructure that requires these headers to identify the application and apply the right policies.

What's the tool?

@aviralgarg05
Copy link
Copy Markdown
Contributor Author

aviralgarg05 commented Feb 5, 2026

The security tool is shared infrastructure that requires these headers to identify the application and apply the right policies.

What's the tool?

The original issue (#16298) describes it as an Istio External Authorizer handling SSO/JWT/SAML. I'm working from that use case rather than a specific deployment, so I don't have the exact tool name—just that it's a shared ExtAuthz service that uses headers like x-accept-auth to determine which auth flow to apply.

@dprotaso
Copy link
Copy Markdown
Member

dprotaso commented Feb 6, 2026

Thanks for the change. But I'm going to close this out as the original issue is actually a big security hole - please see: #16298 (comment)

@dprotaso dprotaso closed this Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow customization in managed VirtualServices #16297

3 participants